package com.transaction.demo.task.scheduled;

import java.time.LocalDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import lombok.extern.slf4j.Slf4j;

import com.transaction.demo.task.service.MessageTaskService;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
@Slf4j
public class MessageTask {

	@Autowired
	private MessageTaskService messageTaskService;

	//3.添加定时任务
	@Scheduled(cron = "0/30 * * * * ?")
	//或直接指定时间间隔，例如：5秒
	//@Scheduled(fixedRate=5000)
	private void handleWaitingConfirmTimeOutMessagesTask() {
		//log.info("处理状态为“待确认”但已超时的消息.: {}", LocalDateTime.now());
		messageTaskService.handleWaitingConfirmTimeOutMessages();
	}

	@Scheduled(cron = "0/60 * * * * ?")
	//或直接指定时间间隔，例如：5秒
	//@Scheduled(fixedRate=5000)
	private void handleSendingTimeOutMessageTask() {
		//log.info("处理状态为“发送中”但超时没有被成功消费确认的消息: {}", LocalDateTime.now());
		messageTaskService.handleSendingTimeOutMessage();
	}
}
